package com.senseu.utils;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.WebElement;

import java.lang.reflect.Field;

public class TapFieldDecorator extends AppiumFieldDecorator {

    private final TapHelper tapHelper;

    public TapFieldDecorator(AppiumDriver driver, TapHelper tapHelper) {
        super(driver);
        this.tapHelper = tapHelper;
    }

    @Override
    public Object decorate(ClassLoader loader, Field field) {
        Object value = super.decorate(loader, field);
        if (value instanceof WebElement) {
            return ElementWrapper.wrap((WebElement) value, tapHelper);
        }
        return value;
    }
}
